#include "start_up_view.h"
#include <stdlib.h>
#include "lv_anim_timeline_wrapper.h"
#include "lv_obj_ext_func.h"

#define COLOR_ORANGE    lv_color_hex(0xff931e)

startup_view_t startup_view_create(lv_obj_t* root)
{
	startup_view_t startup_view;
	
    startup_view.cont = lv_obj_create(root);
    lv_obj_remove_style_all(startup_view.cont);
    lv_obj_clear_flag(startup_view.cont, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_size(startup_view.cont, 140, 50);
    lv_obj_set_style_border_color(startup_view.cont, COLOR_ORANGE, 0);
    lv_obj_set_style_border_side(startup_view.cont, LV_BORDER_SIDE_BOTTOM, 0);
    lv_obj_set_style_border_width(startup_view.cont, 3, 0);
    lv_obj_set_style_border_post(startup_view.cont, true, 0);
    lv_obj_center(startup_view.cont);

		
    startup_view.labelLogo = lv_label_create(startup_view.cont);
    lv_obj_set_style_text_font(startup_view.labelLogo, &lv_font_montserrat_36, 0);
    lv_obj_set_style_text_color(startup_view.labelLogo, COLOR_ORANGE, 0);
    lv_label_set_text(startup_view.labelLogo, "MARCO");
    lv_obj_center(startup_view.labelLogo);

    startup_view.anim_timeline = lv_anim_timeline_create();

#define ANIM_DEF(start_time, obj, attr, start, end) \
     {start_time, obj, LV_ANIM_EXEC(attr), start, end, 500, lv_anim_path_ease_out, true}

    lv_anim_timeline_wrapper_t wrapper[] =
    {
		/* {0, startup_view.cont, (lv_anim_exec_xcb_t)lv_obj_set_width, 0, lv_obj_get_style_width(startup_view.cont, 0),500, lv_anim_path_ease_out, true}, */
        ANIM_DEF(0, startup_view.cont, width, 0, lv_obj_get_style_width(startup_view.cont, 0)),
        ANIM_DEF(500, startup_view.labelLogo, y, lv_obj_get_style_height(startup_view.cont, 0), lv_obj_get_y(startup_view.labelLogo)),
        LV_ANIM_TIMELINE_WRAPPER_END
    };

    lv_anim_timeline_add_wrapper(startup_view.anim_timeline, wrapper);
		
		return startup_view;
}


void startup_view_delete(startup_view_t *startup_view)
{
    if(startup_view->anim_timeline)
    {
        lv_anim_timeline_del(startup_view->anim_timeline);
        startup_view->anim_timeline = NULL;
    }
}

